﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Simple.Repository.Migrations
{
    public partial class _45 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "FoodMaterialsType",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "主键", collation: "ascii_general_ci"),
                    Code = table.Column<string>(type: "longtext", nullable: true, comment: "编号")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Name = table.Column<string>(type: "longtext", nullable: true, comment: "类别名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "软删标记"),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "创建时间"),
                    CreatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "创建用户Id", collation: "ascii_general_ci"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "更新时间"),
                    UpdatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "更新用户Id", collation: "ascii_general_ci"),
                    OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "机构Id", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FoodMaterialsType", x => x.Id);
                },
                comment: "食材分类")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Recipes",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "主键", collation: "ascii_general_ci"),
                    RecipeName = table.Column<string>(type: "longtext", nullable: true, comment: "食谱名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Abbreviation = table.Column<string>(type: "longtext", nullable: true, comment: "简称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "软删标记"),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "创建时间"),
                    CreatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "创建用户Id", collation: "ascii_general_ci"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "更新时间"),
                    UpdatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "更新用户Id", collation: "ascii_general_ci"),
                    OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "机构Id", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Recipes", x => x.Id);
                },
                comment: "食谱")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "FoodMaterials",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "主键", collation: "ascii_general_ci"),
                    FoodName = table.Column<string>(type: "longtext", nullable: true, comment: "食物名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Source = table.Column<int>(type: "int", nullable: false, comment: "来源(0-系统，1-外部)"),
                    FoodDepartment = table.Column<int>(type: "int", nullable: false, comment: "食部"),
                    Heat = table.Column<int>(type: "int", nullable: false, comment: "热量"),
                    Protein = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "蛋白质"),
                    Fat = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "脂肪"),
                    Carbohydrate = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "碳水化合物"),
                    Retinol = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "视黄醇"),
                    Carotene = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "胡萝卜素"),
                    Calcium = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "钙"),
                    Iron = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "铁"),
                    Zinc = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "锌"),
                    Phosphorus = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "磷"),
                    NicotinicAcid = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "尼克酸"),
                    VitA = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "VitA"),
                    VitB1 = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "VitB1"),
                    VitB2 = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "VitB2"),
                    VitC = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "VitC"),
                    FoodMaterialsTypeId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "食材分类", collation: "ascii_general_ci"),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "软删标记"),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "创建时间"),
                    CreatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "创建用户Id", collation: "ascii_general_ci"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "更新时间"),
                    UpdatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "更新用户Id", collation: "ascii_general_ci"),
                    OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "机构Id", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FoodMaterials", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FoodMaterials_FoodMaterialsType_FoodMaterialsTypeId",
                        column: x => x.FoodMaterialsTypeId,
                        principalTable: "FoodMaterialsType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "食材")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "RecipesDetails",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "主键", collation: "ascii_general_ci"),
                    Weight = table.Column<decimal>(type: "decimal(65,30)", nullable: false, comment: "食物重量"),
                    RecipesId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "食谱id", collation: "ascii_general_ci"),
                    FoodMaterialsId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "食材id", collation: "ascii_general_ci"),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "软删标记"),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "创建时间"),
                    CreatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "创建用户Id", collation: "ascii_general_ci"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "更新时间"),
                    UpdatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "更新用户Id", collation: "ascii_general_ci"),
                    OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "机构Id", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RecipesDetails", x => x.Id);
                    table.ForeignKey(
                        name: "FK_RecipesDetails_FoodMaterials_FoodMaterialsId",
                        column: x => x.FoodMaterialsId,
                        principalTable: "FoodMaterials",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_RecipesDetails_Recipes_RecipesId",
                        column: x => x.RecipesId,
                        principalTable: "Recipes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "食谱详情")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.InsertData(
                table: "FoodMaterialsType",
                columns: new[] { "Id", "Code", "CreatedTime", "CreatedUserId", "Name", "OrganizationId", "UpdatedTime", "UpdatedUserId" },
                values: new object[,]
                {
                    { new Guid("00255fcc-a426-40e2-b4f6-a7d32524a967"), "6", null, null, "畜肉类及制品", null, null, null },
                    { new Guid("00ca91a0-14c0-4dc6-a3e8-7d133bd86771"), "3", null, null, "蔬菜类及制品", null, null, null },
                    { new Guid("26bb4bf4-c79e-42d0-bebd-af38b80e84a8"), "5", null, null, "水果类及制品", null, null, null },
                    { new Guid("2c662bff-e3d1-4623-9d9d-a48071c13f27"), "11", null, null, "坚果、种子类", null, null, null },
                    { new Guid("3eb248cd-0ef2-4c35-af0b-2afec6eedb2b"), "16", null, null, "糖、蜜饯类", null, null, null },
                    { new Guid("4c2ab69d-bc4d-433d-b6a7-6c9a087a84ea"), "13", null, null, "小吃、甜饼", null, null, null },
                    { new Guid("51d35687-8036-4453-8387-204709ce0786"), "10", null, null, "干豆类及制品", null, null, null },
                    { new Guid("60afe270-fbea-44f9-86bc-971e69319a56"), "12", null, null, "乳类及制品", null, null, null },
                    { new Guid("6d07a033-a684-4609-9014-868aff54ec3d"), "17", null, null, "动物油脂", null, null, null },
                    { new Guid("70d5673c-380d-4f21-ac1a-4d20f87231b8"), "4", null, null, "菌藻类", null, null, null },
                    { new Guid("7a160cf8-5204-4c34-893a-7e7f05534d26"), "9", null, null, "鱼虾蟹贝类", null, null, null },
                    { new Guid("821721cb-b1bb-4953-abd2-1e9336568224"), "14", null, null, "速食食品", null, null, null },
                    { new Guid("8dc5491c-71c8-4673-b72c-1a0e681b980e"), "19", null, null, "调味品类", null, null, null },
                    { new Guid("981eb19b-92fe-425a-bc1c-0fbc8e03c107"), "18", null, null, "植物油脂", null, null, null },
                    { new Guid("a554242c-59ca-44a6-b1bf-7b5906774cc3"), "20", null, null, "其他", null, null, null },
                    { new Guid("a9907e63-3180-4004-ba34-bc5e3db41531"), "1", null, null, "谷类及制品", null, null, null },
                    { new Guid("bf406e0e-bdc3-4663-b863-9862695c1f2c"), "2", null, null, "薯类、淀粉及制品", null, null, null },
                    { new Guid("dd318da9-48bd-4019-9321-adf7d47453d3"), "7", null, null, "禽肉类及制品", null, null, null },
                    { new Guid("f1d448ec-1287-4064-8b59-d8c5d823235e"), "15", null, null, "饮料类", null, null, null },
                    { new Guid("f4c477d0-ce9e-49e5-bb9b-bce74b905e06"), "8", null, null, "蛋类及制品", null, null, null }
                });

            migrationBuilder.CreateIndex(
                name: "IX_FoodMaterials_FoodMaterialsTypeId",
                table: "FoodMaterials",
                column: "FoodMaterialsTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_RecipesDetails_FoodMaterialsId",
                table: "RecipesDetails",
                column: "FoodMaterialsId");

            migrationBuilder.CreateIndex(
                name: "IX_RecipesDetails_RecipesId",
                table: "RecipesDetails",
                column: "RecipesId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "RecipesDetails");

            migrationBuilder.DropTable(
                name: "FoodMaterials");

            migrationBuilder.DropTable(
                name: "Recipes");

            migrationBuilder.DropTable(
                name: "FoodMaterialsType");
        }
    }
}
